//
//  UIDevice+InfoUtil.m
//  CheFu365
//
//  Created by safiri on 2017/9/2.
//  Copyright © 2017年 safiri. All rights reserved.
//

#import "UIDevice+InfoUtil.h"
#include <sys/sysctl.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>

@implementation UIDevice (InfoUtil)

+ (NSString *)getMobileCountryAndNetworkCode {
    //获取本机运营商名称
    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    
    CTCarrier *carrier = [info subscriberCellularProvider];
    //当前手机所属运营商名称
    
    //NSString *mobile;
    NSString *code;
    //先判断有没有SIM卡，如果没有则不获取本机运营商
    
    if (!carrier.isoCountryCode) {
        NSLog(@"没有SIM卡");
        //mobile = @"无运营商";
        code = @"00000";
    }else{
        //mobile = [carrier carrierName];
        code = [carrier.mobileCountryCode stringByAppendingString:carrier.mobileNetworkCode];
        if (code.length > 5) {
            code = [code substringToIndex:5];
        }else if (code.length < 5) {
            code = @"00000";
        }
    }
    return code;
}

- (NSString *)systemNameAndVersion {
    return [self.systemName stringByAppendingString:[@" " stringByAppendingString:self.systemVersion]];
}


@end
